package com.psfd.demo.controller;

import com.psfd.demo.bean.User;
import com.psfd.demo.service.UserService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.util.List;

@Controller
public class LoginController {

    @Resource
    private UserService userService;

//    @RequestMapping("/login")
//    public String login(User user, Model model){
//        System.out.println(user+"..............");
//        System.out.println("----------------------");
//        List<User> list = userService.list();
//        System.err.println(list.get(0));
//        for (User user1 : list) {
//            if (user1.getName().equals(user.getName()) && user1.getPassword().equals(user.getPassword()) ){
//                    model.addAttribute("userName",user.getName());
//                    return "homepage";
//                }
//        }
//        return "login";
//    }


    @RequestMapping("/login")
    public ModelAndView login(User user){
        ModelAndView andView = new ModelAndView();
            List<User> list = userService.list();
            for (User user1 : list) {
                if (user1.getName().equals(user.getName()) && user1.getPassword().equals(user.getPassword()) ){
                    andView.setViewName("homepage");
                    return andView;
                }
            }
        andView.setViewName("login");
        return andView;
    }
    @RequestMapping("/")
    public String lognPage(){
        return "login";
    }


}
